import { _decorator, Animation, Component, Node } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('AttackAnimation')
export class AttackAnimation extends Component {
    @property(Node)
    weapon: Node = null!;

    animation: Animation = null!;
    onLoad() {
        this.animation = this.weapon.getComponent(Animation)!;
        this.animation.on(
            Animation.EventType.FINISHED,
            this.onFinished,
            this,
        );
    }

    protected start(): void {}

    attack() {
        this.weapon.active = true;
        this.animation.play('attack');
    }

    onFinished() {
        this.weapon.active = false;
    }
}
